import {delMessage, updateMessage} from "@/api/im/message";
import uniCopy from "@/utils/uni-copy";

const TokenKey = 'App-Token'

export function copyMsg(msg) {
    uniCopy({
        content: msg.content,
        success: (res) => {
            uni.showToast({
                title: res,
                icon: 'none'
            })
        },
        error: (e) => {
            uni.showToast({
                title: e,
                icon: 'none',
                duration: 3000,
            })
        }
    })
}

export function deleteMsg(msgs, msg) {
    let newMsgs = [...msgs]
    let index = newMsgs.findIndex(item => item.id === msg.id);
    if (index !== -1) {
        delMessage(msg.id)
        newMsgs.splice(index, 1)
        return newMsgs
    }
}

export function withdrawMsg(msgs, msg) {
    let newMsgs = [...msgs]
    let index = newMsgs.findIndex(item => item.id === msg.id);
    if (index !== -1) {
        newMsgs[index].status = 2
        updateMessage(newMsgs[index])
        return newMsgs
    }
}
